//
//  VoteView.m
//  LastOne
//
//  Created by dllo on 15/11/10.
//  Copyright © 2015年 sc. All rights reserved.
//

#import "VoteView.h"
#import "FitHeader.h"
#define PI 3.14159265358979323846
//把角度转化为弧度的公式
static inline float radians(int degrees)
{
    return degrees * M_PI / 180;
    
}
@implementation VoteView
- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        
     
        _circleLabel = [[UILabel alloc]initWithFrame:CGRectMake(10 * FitWidth, 3 * FitHeight, 50 * FitWidth, 50 * FitHeight)];
       
        _circleLabel.layer.cornerRadius = 25;
        _circleLabel.clipsToBounds = YES;
        [self addSubview:_circleLabel];
        
        _messageLabel = [[UILabel alloc]initWithFrame:CGRectMake(65 * FitWidth, 8 * FitHeight, 200 * FitWidth, 20 * FitHeight)];
       
        [self addSubview:_messageLabel];
        
        _percentLabel = [[UILabel alloc]initWithFrame:CGRectMake(65 * FitWidth, 28 * FitHeight, 200 * FitWidth, 20 * FitHeight)];
        
        [self addSubview:_percentLabel];
        self.backgroundColor = [UIColor whiteColor];
        
    }
    return self;
    
    
    
    
    
    
}
-(void)drawRect:(CGRect)rect
{
    

    CGContextRef context = UIGraphicsGetCurrentContext();
    //边线的颜色
    CGContextSetRGBFillColor(context, 1, 0, 0, 1.0);
    UIColor  *color = [UIColor colorWithRed:0 green:1 blue:1 alpha:1];
    //填充的颜色
    CGContextSetFillColorWithColor(context, color.CGColor);
    //扇形的圆心
    
    CGContextMoveToPoint(context, _circleLabel.center.x, _circleLabel.center.y  );
    //扇形的角度 0是逆时针 1是顺时针
    CGFloat i = 1.0 * _y / 100 * 360 - 90;
    CGContextAddArc(context, _circleLabel.center.x, _circleLabel.center.y , 25, -90 * M_PI / 180, i * M_PI / 180, 1);
    CGContextClosePath(context);
    
    CGContextDrawPath(context, kCGPathFillStroke);
    
}


@end
